package com.qianfeng.controller;

import com.qianfeng.dto.R;
import com.qianfeng.log.annotations.LogAnnotation;
import com.qianfeng.pojo.Scene;
import com.qianfeng.service.SceneService;
import com.qianfeng.valigroup.Delete;
import com.qianfeng.valigroup.UpDate;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
 *@Description:
 *@author:刘哥
 *@Date:86180 2022/9/8 15:29
 */
@RestController
@RequestMapping("/scenes")
@Api(tags = "场景管理模块")
public class SceneController {
    private SceneService sceneService;

    @Autowired
    public void setSenceService(SceneService sceneService) {
        this.sceneService = sceneService;
    }

    @PostMapping("/scene")
    @LogAnnotation(title = "添加场景",business_type = 1)
    public R addScene(@Validated @RequestBody Scene scene){
        sceneService.addScene(scene);
        return R.OK();
    }
    @GetMapping("/scene/{sceneId}")
    @LogAnnotation(title = "查询场景",business_type = 0)
    public R findById(@PathVariable Long sceneId){

        return R.OK(sceneService.findById(sceneId));
    }
    @GetMapping("/scene")
    @LogAnnotation(title = "查询所有场景",business_type = 0)
    public R findAll(){
        return R.OK(sceneService.getSceneAll());
    }

    @DeleteMapping("/scene/{sceneId}")
    @LogAnnotation(title = "删除场景",business_type = 3)
    public R deleteById(@Validated(Delete.class) @PathVariable Long sceneId){
        sceneService.deleteById(sceneId);
        return R.OK();
    }
    @PutMapping("/scene")
    @LogAnnotation(title = "修改场景",business_type = 2)
    public R update(@RequestBody Scene scene){
        sceneService.updateById(scene);
        return R.OK();
    }
}
